#include "Metgine/Core/TextResource.hpp"

namespace Metgine
{
namespace Core
{

TextResource::TextResource(const std::string& path) : Resource(ResourceType::Text)
{

    std::ifstream fs(path.c_str(), std::ios_base::in);
    char buffer[1024];
    std::string line;

    if (fs.is_open())
    {

        while (fs.getline(buffer, 1024))
        {

            line = buffer;
            m_lines.push_back(line);

        }

        fs.close();

    }

    m_empty = "";

}

TextResource::TextResource(const std::vector<std::string>& strings) : Resource(ResourceType::Text)
{

    std::string line;
    for (unsigned int i = 0; i < strings.size(); ++ i)
    {
        line = strings[i];

        m_lines.push_back(line);

    }

    m_empty = "";
}

const std::string& TextResource::GetLine(unsigned int index)
{

    if ((index >= 0) && (index < m_lines.size()))
    {
        return m_lines[index];
    }

    return m_empty;

}

unsigned int TextResource::GetNumLines() const
{

    return m_lines.size();

}

}; // Core
}; // Metgine
